package org.budo.weibo.api;

import org.budo.support.http.client.HttpUtil;
import org.budo.support.http.client.Response;
import org.budo.weibo.response.AccessTokenResponse;
import org.budo.weibo.response.GetUidResponse;

/**
 * @author lmw
 */
public class WeiboOauthApi extends AbstractWeiboApi {
    public AccessTokenResponse accessToken(String code) {
        String url = "https://api.weibo.com/oauth2/access_token" //
                + "?client_id=" + this.getAppKey() //
                + "&client_secret=" + this.getAppSecret() //
                + "&grant_type=authorization_code" //
                + "&redirect_uri=" + this.getRedirectUri() //
                + "&code=" + code;

        Response response = HttpUtil.post(url);
        return new AccessTokenResponse(response);
    }

    public GetUidResponse getUid(String accessToken) {
        String url = "https://api.weibo.com/2/account/get_uid.json?access_token=" + accessToken;
        Response response = HttpUtil.get(url);
        return new GetUidResponse(response);
    }
}